// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Conveyor Wheel Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 71 : TYPE_CONVEYORWHEEL

// Function declarations
reserve function ConveyorWheel_DebugDraw
reserve function ConveyorWheel_DebugSpawn

// Static Values

// Tables

function ConveyorWheel_DebugDraw
	DrawSprite(0)
end function


function ConveyorWheel_DebugSpawn
	CreateTempObject(TypeName[Conveyor Wheel], 0, object.xpos, object.ypos)
	object[tempObjectPos].drawOrder = 5
end function


event ObjectMain
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -64, -64, 64, 64, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 1
			if object[currentPlayer].gravity == GRAVITY_GROUND
				if object[currentPlayer].state == PlayerObject_KnuxGlideSlide
					object[currentPlayer].state = PlayerObject_HandleGround
				end if
				if object[currentPlayer].state == PlayerObject_KnuxGlideDrop
					object[currentPlayer].state = PlayerObject_HandleGround
				end if
				if object[currentPlayer].speed < 0x40000
					object[currentPlayer].speed = 0x40000
				else
					if object[currentPlayer].speed > 0xF0000
						object[currentPlayer].speed = 0xF0000
					end if
				end if
			end if
		end if
	next
	object.angle += 4
	object.angle &= 511
end event


event ObjectDraw
	Cos(temp0, object.angle)
	temp0 *= 0xC00
	temp0 += object.xpos
	Sin(temp1, object.angle)
	temp1 *= 0xC00
	temp1 += object.ypos
	DrawSpriteXY(0, temp0, temp1)
end event


event ObjectStartup
	LoadSpriteSheet("SBZ/Objects.gif")
	SpriteFrame(-7, -7, 14, 14, 65, 123)
	foreach (TypeName[Conveyor Wheel], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 5
	next
	SetTableValue(TypeName[Conveyor Wheel], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(ConveyorWheel_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(ConveyorWheel_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
